package aquarium.items;

import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.net.URL;
import java.util.Collection;

import aquarium.time.TManager;


public class PiscivoreFish extends Fish {

	private static URL _url = ClassLoader.getSystemResource("image/drole_vert_fish.png");
	private static URL _url_visitor = ClassLoader.getSystemResource("image/drole_vert_fish_visitor.png");
	private static Image _fishImage = Toolkit.getDefaultToolkit().createImage(_url);
	private static Image _fishImage_visitor = Toolkit.getDefaultToolkit().createImage(_url_visitor);

	public PiscivoreFish(Point position, int size, long move_delay, 
			long change_target_delay, Point target, Sex sex, boolean visitor, TManager tmanager) {
		super(_fishImage, position, size, true, false, move_delay, change_target_delay, target, true,
				false, sex, visitor, tmanager);
		if (visitor)
			this.set_image(_fishImage_visitor);
	}

	@Override
	public void move(Collection<AquariumItem> neighbours) {
		super.move(neighbours);		
	}

	public void newTarget(Collection<AquariumItem> items){
		boolean find = false;
		synchronized(items){
		for(AquariumItem it : items) // Recherche des poissons Piscivores
			if (it.is_destructible() &&  ((Fish)it).is_eatable() && it.get_size() < this.get_size()){ // La on a trouvé un Piscivore
				get_target().setLocation(it.get_position());
				find = true;
			}
		}
		if(!find)
			if (this.get_target().equals(this.get_position()))
				super.newTarget(items);
	}

}
